package com.inke.box.login;


import com.blankj.utilcode.util.ToastUtils;
import com.inke.box.login.vo.InKe_User;
import com.inke.box.net.HttpCallBack;
import com.inke.box.net.InKeHttp;
import com.tsy.sdk.myokhttp.MyOkHttp;

import java.util.HashMap;

import mvp.BasePresenterImpl;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class LoginPresenter extends BasePresenterImpl<LoginContract.View> implements LoginContract.Presenter{

    public String RequestTag = "login";
    private MyOkHttp myOkHttp;
    @Override
    public void login(String user, String password) {

        HashMap hashMap = new HashMap();
        myOkHttp = InKeHttp.getInstence().loginHttpRequest(hashMap, new HttpCallBack() {
            @Override
            public void onSucceed(int statusCode, Object t) {
                ToastUtils.showShort("成功");
                //Activity逻辑回调
                mView.loginSucceed((InKe_User)t);

            }

            @Override
            public void onFailure(int statusCode, String erromsg) {
                ToastUtils.showShort("失败:"+statusCode);
                mView.loginErr("账号或密码错误！");
            }

            @Override
            public void onNetWorkAvailable() {
                ToastUtils.showShort("网络不可用");
            }
        },RequestTag);

    }

    @Override
    public void cancleLogin() {
        myOkHttp.cancel(RequestTag);
    }
}
